package com.bdth.bdthmall.api.epoint.controller;

import com.alibaba.fastjson.JSONObject;
import com.bdth.bdthmall.api.annotation.AuthToken;
import com.bdth.bdthmall.api.epoint.vo.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2020/1/14.
 */
@RestController
@RequestMapping("/ecservice")
public class AddressController {

    @RequestMapping(value = "/getProvinceInfo", method = RequestMethod.POST)
    @AuthToken
    public ResponseProvinceInfoVo getProvinceInfo(@RequestParam String data){
        JSONObject json = JSONObject.parseObject(data);
        ResponseProvinceInfoVo provinceInfoVo = new ResponseProvinceInfoVo();
        provinceInfoVo.setIsSuccess(true);
        provinceInfoVo.setReturnMsg("查询省信息");
        List<ProvinceInfoVo> list = new ArrayList<>();
        ProvinceInfoVo infoVo1 = new ProvinceInfoVo("2","北京");
        ProvinceInfoVo infoVo2 = new ProvinceInfoVo("3","安徽");
        list.add(infoVo1);
        list.add(infoVo2);
        provinceInfoVo.setProvince(list);
        return provinceInfoVo;
    }

    @RequestMapping(value = "/getCityInfo", method = RequestMethod.POST)
    @AuthToken
    public ResponseCityInfoVo getCityInfo(@RequestParam String data){
        JSONObject json = JSONObject.parseObject(data);
        String provinceId = json.getString("provinceId");
        System.out.println("provinceId:"+provinceId);
        ResponseCityInfoVo cityInfoVo = new ResponseCityInfoVo();
        cityInfoVo.setIsSuccess(true);
        cityInfoVo.setReturnMsg("查询市信息");
        List<CityInfoVo> list = new ArrayList<>();
        CityInfoVo infoVo1 = new CityInfoVo("102","合肥");
        CityInfoVo infoVo2 = new CityInfoVo("103","黄山");
        list.add(infoVo1);
        list.add(infoVo2);
        cityInfoVo.setCity(list);
        return cityInfoVo;
    }

    @RequestMapping(value = "/getDistrictInfo", method = RequestMethod.POST)
    @AuthToken
    public ResponseDistrictInfoVo getDistrictInfo(@RequestParam String data){
        JSONObject json = JSONObject.parseObject(data);
        String cityId = json.getString("cityId");
        System.out.println("cityId:"+cityId);
        ResponseDistrictInfoVo districtInfoVo = new ResponseDistrictInfoVo();
        districtInfoVo.setIsSuccess(true);
        districtInfoVo.setReturnMsg("查询地区信息");
        List<DistrictInfoVo> list = new ArrayList<>();
        DistrictInfoVo infoVo1 = new DistrictInfoVo("1002","滨湖区");
        DistrictInfoVo infoVo2 = new DistrictInfoVo("1003","市区");
        list.add(infoVo1);
        list.add(infoVo2);
        districtInfoVo.setDistrict(list);
        return districtInfoVo;
    }

    @RequestMapping(value = "/getTownInfo", method = RequestMethod.POST)
    @AuthToken
    public ResponseTownInfoVo getTownInfo(@RequestParam String data){
        JSONObject json = JSONObject.parseObject(data);
        String countyId = json.getString("countyId");
        System.out.println("countyId:"+countyId);
        String cityId = json.getString("cityId");
        System.out.println("cityId:"+cityId);
        ResponseTownInfoVo townInfoVo = new ResponseTownInfoVo();
        townInfoVo.setIsSuccess(true);
        townInfoVo.setReturnMsg("查询乡镇信息");
        List<TownInfoVo> list = new ArrayList<>();
        TownInfoVo infoVo1 = new TownInfoVo("10021","测试镇1");
        TownInfoVo infoVo2 = new TownInfoVo("10031","测试镇2");
        list.add(infoVo1);
        list.add(infoVo2);
        townInfoVo.setTown(list);
        return townInfoVo;
    }
}
